home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12062 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  59 lines

  1. Path: nntp.teleport.com!qp7
  2. From: qp7@teleport.com (QP7)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: DOS Like Pipe Operator In C++??
  5. Date: 18 Mar 1996 03:04:21 GMT
  6. Organization: SHATTERED PERSPECTIVES GAMES
  7. Message-ID: <4iijrl$ept@nadine.teleport.com>
  8. References: <4iffh3$p01@netaxs.com>
  9. NNTP-Posting-Host: ip-pdx01-32.teleport.com
  10. X-Newsreader: News Xpress Version 1.0 Beta #3
  11.  
  12. In article <4iffh3$p01@netaxs.com>, rvaughn@pacsibm.org (RussellMania) wrote:
  13. >class world {
  14. >      int x;
  15. >    public:
  16. >      world(int a)      { x = a; }
  17. >      void set(int xx)  { x = xx; }
  18. >};
  19. >class hello {
  20. >      int x;
  21. >      world view;  // define an object as a private member 
  22. >    public:
  23. >      void set(int x)    { view.set(x); }    // set function
  24. >      int y;                    // data member
  25. >      hello(int z):view(z)  { x = 57; y = 66; }  // constructor??
  26. >      void display()   {cout << x << " " << y << '\n'; view.display(;}
  27. >};
  28. >void main(void)
  29. >{ hello peace(55); peace.display(); }
  30. >Outputs are 57 66
  31. >        and 55
  32. >Is the : character in the constructor of class hello acting as
  33. >a pipe?  Thanks again for all replies...Russell
  34.  
  35. You mean like an OR pipe?  No.  This line is the constructor for the hello 
  36. class, which accepts an integer (z) initializer.  The class view is being 
  37. initialized when hello is.  All that you're doing here is initializing view 
  38. with the initializer passed to hello.  Another way of writing this constructor 
  39. is:
  40.  
  41. hello(int z) { 
  42.   view(z);
  43.   x = 57;  y = 66;
  44. }
  45.  
  46. You get the same effect, but it's better to intialized encapsulated classes 
  47. from the constructor using this initializer list.  You can also intialize data 
  48. members using the exact same method.  
  49.  
  50. - QP7 -
  51.  
  52. ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
  53. - Marcus Litchfield
  54. - qp7@teleport.com
  55. - http://www.teleport.com/~qp7
  56.      (                  |_)
  57.       )hattered     | erspectives
  58. [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
  59.